package recursion;

public class Summary {

    public static int sum(int[] data) {
        return sum(data, 0);
    }

    // 宏观语义：计算数组data[l, data.length)的和
    // => result = data[l] + data[l + 1, data.length)的和
    // => 终止: l == data.length
    private static int sum(int[] data, int l) {
        if (l == data.length) return 0;
        return data[l] + sum(data, l + 1);
    }

    public static void main(String[] args) {
        System.out.println(sum(new int[]{1, 2, 3}));
    }
}
